import {
	API_URL,
	IMG_URL
} from '../../env.js'
//时间过滤函数
function alltime(value) {
	var unixTimestamp = new Date(value * 1000);
	var year = unixTimestamp.getFullYear()

	var month = unixTimestamp.getMonth() + 1
	month > 9 ? '' : month = '0' + month
	var date = unixTimestamp.getDate()
	date > 9 ? '' : date = '0' + date
	var hour = unixTimestamp.getHours()
	hour > 9 ? '' : hour = '0' + hour
	var min = unixTimestamp.getMinutes()
	min > 9 ? '' : min = '0' + min
	var sec = unixTimestamp.getSeconds()
	sec > 9 ? '' : sec = '0' + sec



	let commonTime = year + "-" + month + "-" + date + '  ' + hour + ':' +
		min + ':' + sec
	return commonTime
}

function time(value) {
	var unixTimestamp = new Date(value * 1000);
	var year = unixTimestamp.getFullYear()

	var month = unixTimestamp.getMonth() + 1
	month > 9 ? '' : month = '0' + month
	var date = unixTimestamp.getDate()
	date > 9 ? '' : date = '0' + date
	var hour = unixTimestamp.getHours()
	hour > 9 ? '' : hour = '0' + hour
	var min = unixTimestamp.getMinutes()
	min > 9 ? '' : min = '0' + min
	var sec = unixTimestamp.getSeconds()
	sec > 9 ? '' : sec = '0' + sec



	let commonTime = year + "-" + month + "-" + date
	return commonTime
}
//判断图片是否加了域名
function imgHeader(value = '') {
	var a = value.slice(0, 4)
	let b = value.slice(0,1)
	if(value == ''){
		return '/static/image/loading.gif'
	}else{
		if (a === 'http' || b !='/') {
			return value
		} else if (value) {
			return IMG_URL + value
		}
	}
}
//判断图片是否加了域名
function avatarHeader(value = '') {
	var a = value.slice(0, 4)
	let b = value.slice(0,1)
	if(value == ''){
		return '/static/image/user.png'
	}else{
		if (a === 'http' || b!='/') {
			return value
		} else if (value) {
			return IMG_URL + value
		}
	}
	
}


//价格格式处理
function price(value = '0.00') {
	var result = ''
	if (parseInt(value) === parseFloat(value)) {
		result = parseInt(value)
	} else {
		result = value
	}
	return result
}

export default {
	alltime,
	time,
	imgHeader,
	avatarHeader,
	price
}